import service from './axios'

//---Order部分---start
//获取所有订单信息
export const getAllOrders = () => {
  return service({
    url: '/order/orders',
    method: 'get'
  })
}

//通过username获得所有订单信息
export const getAllOrdersByUsername = (username) => {
  return service({
    url: '/account/orders/' + username ,
    method: 'get'
  })
}

//获取指定订单信息
export const getOrderById = (orderid) => {
  return service({
    url: '/order/orders/' + orderid,
    method: 'get'
  })
}

//退货
export const cancelOrderById = (orderid) => {
  return service({
    url: '/order/orders/cancel/' + orderid,
    method: 'get'
  })
}

//收货
export const receiveOrderById = (orderid) => {
  return service({
    url: '/order/orders/receive/' + orderid,
    method: 'get'
  })
}

//添加一个订单
export const postOrder = (order) => {
  return service({
    url: '/order/orders',
    method: 'post',
    data: order
  })
}

//更新指定订单
export const updateOrderById = (orderid, order) => {
  return service({
    url: '/order/orders/' + orderid,
    method: 'put',
    data: order
  })
}

//删除指定订单
export const deleteOrderById = (orderid) => {
  return service({
    url: '/order/orders/' + orderid,
    method: 'delete'
  })
}

//---Order部分---end

//---Catalog部分---start

//获取大类信息
export const getCategoryByCategoryId = (id) => {
  return service({
    url: '/catalog/categories/' + id,
    method: 'get'
  })
}

//通过大类获取小类（用categoryId拿到productList）
export const getProductByCategoryId = (id) => {
  return service({
    url: '/catalog/categories/' + id + '/products',
    method: 'get'
  })
}

//获取小类信息
export const getProductByProductId = (id) => {
  return service({
    url: '/catalog/products/' + id,
    method: 'get'
  })
}

//通过小类获取商品列表
export const getItemByProductId = (id) => {
  return service({
    url: '/catalog/products/' + id + '/items',
    method: 'get'
  })
}

//通过id(itemId)获取商品信息
export const getItemByItemId = (id) => {
  return service({
    url: '/catalog/items/' + id,
    method: 'get'
  })
}

//---Catalog部分---end

//---Cart部分---start
//获取购物车
export const getCartByUsername = (username) => {
  return service({
    url: '/cart/' + username + '/cartItems',
    method: 'get'
  })
}

//添加商品到购物车
export const addItemToCart = (username,itemId,increment) => {
  return service({
    url: '/cart/' + username + '/cartItems/' + itemId,
    method: 'post',
    data:increment

  })
}

//从购物车中删除某一个商品
export const deleteItemFromCart = (username,itemId) => {
  return service({
    url: '/cart/' + username + '/cartItems' + itemId,
    method: 'delete'
  })
}

//更新购物车商品数量
export const updateCart = (username,itemId,param) => {
  return service({
    url: '/cart/' + username + '/cartItems/' + itemId,
    method: 'patch',
    data: param
  })
}

//清空购物车
export const deleteAllCart = (username) => {
  return service({
    url: '/cart/' + username + '/cartItems',
    method: 'delete'
  })
}

//---Cart部分---end

//---Pay部分---start
export const aliPay = (orderPay) => {
  return service({
    url: '/alipay/pay',
    method: 'post',
    data: orderPay
  })
}
//---Pay部分---end

export  const addItemToCollect = (username,itemid) => {
  return service({
    url: '/collect/collects/'+username +'/'+ itemid,
    method: 'post'
  })

}

export  const deleteItemfromCollect = (username,itemid) => {
  return service({
    url: '/collect/collects/'+username + '/'+itemid,
    method: 'delete'
  })

}
export  const getAllCollectbyId = (username) => {
  return service({
    url: '/collect/collects/'+username,
    method: 'get'
  })

}
export  const getCertainCollect = (username,itemid) => {
  return service({
    url: '/collect/collects/'+username + '/'+itemid,
    method: 'get'
  })

}

export  const checkInCollect = (username,itemid) => {
  return service({
    url: '/collect/items/'+username +'/'+itemid,
    method: 'get'
  })

}

export const updateAccount=(user)=>{
  return service({
    url: '/account/get_login_account_update',
    method: 'post',
    data: user
  })
}


export const addAccount=(param)=>{
  return service({
    url: '/account/register',
    method: 'post',
    data:param,
  })
}

export const loginAccount=(param)=>{
  return service({
    url: '/account/login',
    method: 'post',
    data: param
  })
}
export const getAccount=()=>{
  return service({
    url: '/account/get_login_account_info',
    method: 'post'
  })
}
export const signOutAccount=()=> {
  return service({
    url: '/account/signOut',
    method: 'post'
  })
}

  export const checkUsername = (username) => {
    return service({
      url: '/account/accounts/' + username,
      method: 'get',
    })
  }
    export const checkPhone = (phone) => {
      return service({
        url: '/account/accounts/username/' + phone,
        method: 'get',
      })
    }
//---Comment部分---start

//获取某item的所有评论
export  const getAllCommentByItemId = (itemid) => {
  return service({
    url: '/comment/comments/itemid/'+ itemid,
    method: 'get'
  })
}
export const checkVerification = (cacheCode) => {
  return service({
    url: '/account/verification/' + cacheCode,
    method: 'post'
  })
}
export const getNode = (phone) => {
  return service({
    url: '/account/getNode/' + phone,
    method: 'post'
  })
}

  export const bendNode = (phone) => {
    return service({
      url: '/account/tiePhone/' + phone,
      method: 'post'
    })
}

export const getAccountByPhone = (phone) => {
  return service({
    url: '/account/get_account_by_phone/' + phone,
    method: 'post'
  })
}

//获取某用户的所有评论
export  const getAllCommentByUsername = (username) => {
  return service({
    url: '/comment/comments/username/'+ username,
    method: 'get'
  })
}

//新增一条评论
export const addCommentToItem = (comment) => {
  return service({
    url: '/comment/comments',
    method: 'post',
    data: comment
  })
}

//删除指定评论
export const deleteMyComment = (commentid) => {
  return service({
    url: '/comment/comments/' + commentid,
    method: 'delete'
  })
}

//---comment部分---end
